package com.linser.gistools.common.datastore.model;

import org.geotools.data.DataAccessFactory;

/**
 * @author: linser
 * @Desc:数据库详细描述信息
 * @create: 2024-01-27 14:10
 **/
public class DbInfo implements Cloneable {
    //唯一值
    private String uuid;

    private DataAccessFactory.Param dbType;

    /**
     * Connection name
     */
    private String name;
    /**
     * Connection comment
     */
    private String comment;
    /**
     * Connection host
     */
    private String host;
    /**
     * Username
     */
    private String username;
    /**
     * Connection password
     */
    private String password;
    /**
     * Connection database
     */
    private String database;
    /**
     * Connection port
     */
    private Integer port;

    private String schema;
    /**
     * Is local storage
     */
    private Boolean local;
//    protected DatabaseConnection databaseConnection = null;

    public DataAccessFactory.Param getDbType() {
        return this.dbType;
    }

    /**
     * Update current database instance every field value
     *
     * @param info {@link DbInfo}
     */
    public void updateField(DbInfo info) {
        this.name = info.name;
        this.host = info.host;
        this.port = info.port;
        this.uuid = info.uuid;
        this.dbType = info.dbType;
        this.username = info.username;
        this.password = info.password;
        this.database = info.database;
        this.comment = info.comment;
    }

    public void setDBType(DataAccessFactory.Param dbType) {
        this.dbType = dbType;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getComment() {
        return comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getDatabase() {
        return database;
    }

    public void setDatabase(String database) {
        this.database = database;
    }

    public Integer getPort() {
        return port;
    }

    public void setPort(Integer port) {
        this.port = port;
    }


    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getUuid() {
        return uuid;
    }

    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    public String getSchema() {
        return schema;
    }

    public void setSchema(String schema) {
        this.schema = schema;
    }

    @Override
    public String toString() {
        return "DbInfo{" +
                "client=" + dbType.sample +
                ", name='" + name + '\'' +
                ", comment='" + comment + '\'' +
                ", host='" + host + '\'' +
                ", password='" + password + '\'' +
                ", database='" + database + '\'' +
                ", port=" + port +
                ", local=" + local +
                '}';
    }

    @Override
    public DbInfo clone() {
        try {
            DbInfo clone = (DbInfo) super.clone();
            // TODO: 复制此处的可变状态，这样此克隆就不能更改初始克隆的内部项
            return clone;
        } catch (CloneNotSupportedException e) {
            throw new AssertionError();
        }
    }
}
